package com.hlingsoft.cms.service;

import com.hlingsoft.cms.constant.OrderInfoConstant;
import com.hlingsoft.cms.dao.OrderInfoDao;
import com.hlingsoft.cms.entity.OrderInfo;

import com.hlingsoft.cms.util.Common;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Service;


import java.util.*;

/**
* Created by selbylei on 2015/5/27.
*/
@Service
public class OrderInfoService extends QuartzJobBean {




    private OrderInfoDao orderInfoDao;
    public void setOrderInfoDao(OrderInfoDao orderInfoDao) {
        this.orderInfoDao = orderInfoDao;
    }

    //重写其默认执行的方法
    protected void executeInternal(JobExecutionContext arg0)
            throws JobExecutionException {
        List<OrderInfo> orderInfoList = orderInfoDao.getWaitPayOrderList();
        for (OrderInfo orderInfo:orderInfoList){
            System.out.println(orderInfo.getOrderId());
            if (Common.diffTime(orderInfo.getCreateTime(),new Date())/60>30){
                orderInfo.setStatus(OrderInfoConstant.OVERDUE);
                orderInfoDao.updateOrderInfo(orderInfo);
                String log="订单:"+orderInfo.getOrderId()+"设置为过期";
                System.out.println(log);
            }
        }
    }


}
